home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 717 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. From: chase@centerline.com (David Chase)
  2. Message-ID: <4i9g94$4v4@wcap.centerline.com>
  3. X-Original-Date: 14 Mar 1996 16:08:04 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 14 Mar 96 16:47:37 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Exception handling -- was a finally block e
  9. Organization: CenterLine Software
  10. References: <31475017.8100207@nntp.ix.netcom.com>
  11. Reply-To: chase@centerline.com
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMUhNvOEDnX0m9pzZAQFchwF/QutqI7EdmbQDJsZAF0J084/VbzGl1DWT
  14.     d1fv/YXbDEGtBIKJuL1EIN+qrnG22UcG
  15.     =3rPY
  16.  
  17. In article 8100207@nntp.ix.netcom.com, jdmorris@ix.netcom.com
  18. (Jason D. Morris) writes:
  19. > I would like to know if the following construct was ever considered by
  20. > the C++ and if it was, why it was rejected.
  21. > try
  22. > { }
  23. > catch ( // some expected exception type )
  24. > {}
  25. > finally
  26. > {
  27. >     // code that would be guaranteed to execute no matter how the 
  28. >     // function was exited.
  29. > }
  30. > Basically, a Java style finally clause.  I also found it interesting
  31. > that Microsoft's structured exception handling under Win32 includes a
  32. > finally clause.
  33.  
  34. Why, I'm not sure.  One possibility might be that it was judged to be
  35. not necessary, because you can get the same effect in other ways.
  36.  
  37. You can get the same effect if you wrap the try-catch up in a block that
  38. contains a local variable with an object type that does what you need.
  39. As in:
  40.  
  41.   {
  42.     class fin {
  43.        public:
  44.        ~fin() {
  45.          ...
  46.        }
  47.        fin( parameters ) {
  48.          ...
  49.        }
  50.     };
  51.  
  52.     fin finally(parameters);
  53.  
  54.     try {} catch {}
  55.  
  56.   } // finally's destructor will be run here.
  57.  
  58. This is not going to win any beauty contests, of course, but what
  59. did you expect?
  60.  
  61. speaking for myself,
  62.  
  63. David Chase
  64. ---
  65. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  66. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  67. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  68. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  69. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  70.